
package com.medranocg.gd.crecerxxi

import com.medranocg.gd.Customer

import coop.bancocredicoop.crecerxxi.server.XStreamSerializer;
import coop.bancocredicoop.crecerxxi.server.exposicion.ResponseTO;
import coop.bancocredicoop.service.core.response.OutputMessage;
import coop.bancocredicoop.service.core.sender.backport.socket.BackportMessageSender;
import coop.bancocredicoop.service.load.ServiceProvider;
import coop.bancocredicoop.service.transaccion.persona.factory.T24MessageSpecFactory;
import coop.bancocredicoop.service.transaccion.persona.parser.spec.ListaCandidatosMessageSpec;
import coop.bancocredicoop.service.transaccion.persona.specParser.ListaCandidatosTextBeanImpl;

class CrecerXXIMock {

	def findCustomerByIdPersona(String tipoPersona, Long idPersona) {

		[new CrecerXXICustomer(idPersona, "denominacion ${idPersona}", "30${idPersona}3")]

    }

    def findCustomerByCuit(String tipoPersona, String cuit) {

		[new CrecerXXICustomer(1, 'nombre A', '30000000013'),
				new CrecerXXICustomer(2, 'nombre B', '30000000023')]

    }

	def findCustomerByNombre(String tipoPersona, String nombre) {

		[new CrecerXXICustomer(1, 'nombre A', '30000000013'),
				new CrecerXXICustomer(2, 'nombre B', '30000000023')]

   }
	
    def findOrCreateCustomer(Long idPersona) {
        def customer = Customer.findByIdPersona(idPersona)
        
        if (customer == null) {
			println 'A'
            def customerProperties = findCustomerByIdPersona('A', idPersona)[0]
			println customerProperties
            def newCustomer = new Customer(
                         idPersona: customerProperties.internalId,
                         cuit: customerProperties.cuit,
                         name: customerProperties.name)
            newCustomer.save(flush: true, failOnError: true)
            return newCustomer
        }

        customer

    }

}
